package com.ruoyi.biz.export.enums;

import cn.hutool.extra.spring.SpringUtil;
import com.ruoyi.biz.export.executor.AbstractExecutor;
import com.ruoyi.biz.export.executor.ClaimExecutor;
import com.ruoyi.biz.export.executor.DispatchExecutor;
import com.ruoyi.biz.letter.export.BizCityLetterExport;
import com.ruoyi.common.exception.ServiceException;

/**
 * @author Fei.Cong
 * @date 2024-07-16 20:03
 */
public enum ExportTemplateEnum {

    CLAIM("CLAIM", "认领", "/template/city_claim_template.xlsx", BizCityLetterExport.class, ClaimExecutor.class),
    DISPATCH("DISPATCH", "调度", "/template/city_dispatch_template.xlsx", BizCityLetterExport.class, DispatchExecutor.class),
    ;

    String type;
    String name;
    String template;
    Class clazz;
    Class objClazz;

    ExportTemplateEnum(String type, String name, String template, Class pClazz, Class clazz) {
        this.type = type;
        this.name = name;
        this.template = template;
        this.clazz = clazz;
        this.objClazz = pClazz;
    }

    public Class getObjClazz() {
        return objClazz;
    }

    public String getTemplate() {
        return template;
    }

    public String getType() {
        return type;
    }

    public String getName() {
        return name;
    }

    public Class getClazz() {
        return clazz;
    }

    public static ExportTemplateEnum getType(String code) {
        for (ExportTemplateEnum type : values()) {
            if (type.type.equals(code)) {
                return type;
            }
        }
        throw new ServiceException("未找到模板,请联系管理员");
    }

    public static AbstractExecutor getTemplateType(String type) {
        ExportTemplateEnum[] values = ExportTemplateEnum.values();
        for (ExportTemplateEnum value : values) {
            if (value.getType().equals(type)) {
                return (AbstractExecutor) SpringUtil.getBean(value.getClazz());
            }
        }
        throw new ServiceException("未找到模板,请联系管理员");
    }
}
